Skip to content

Multiple Importmaps #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henrikbjorn
Copy link

Recently the preload option was merged. But it comes with a huge penalty for a mental model. It is required for each dependency to set the preload for entrypoints. Depending on the number of items it can be hard to follow.

Instead I believe this complexity can be solved with allowing multiple importmaps. But by default just work with a single one like today.

This removes the mental headache since a the dependencies in config/importmaps/admin.rb can be seen as a group. Without reading each preload option.

This also allows to silo each importmap and reduce different dependencies to interfere with each other (e.g admin vs application).

If needed multiple importmaps can be defined in the `config/importmaps`
directory.

`bin/importmap` have a new option to work with named importmaps
`bin/importmap -i admin pin "some-dependency"`

The default is still `config/importmap.rb` so no change for exisiting users
that does not need multiple importmaps or complexity.
@henrikbjorn
Copy link
Author

@dhh would you consider this implementation, since it won't change anything regarding the current usage?

@henrikbjorn
Copy link
Author

This could also make 3rd party gems such as ActiveAdmin make it easier to work with their importmaps. As they can create a config/importmaps/active_admin.rb as part of the install and then allow developers to work with it through the CLI bin/importmap -i active_admin pin json_view

@vfonic
Copy link

vfonic commented Apr 30, 2025

We are having this conversation in ActiveAdmin discussion thread here: activeadmin/activeadmin#8694

This would allow us to separate ActiveAdmin from frontend importmap. Currently, ActiveAdmin v4 requires importmap-rails in order to work. The issue is that <%= javascript_importmap_tags %> "leaks" the entire config/importmap.rb mapping wherever it's included. More info in the discussion thread.

How can we push this forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants